package com.my.screenadapter.myHandler;

import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.my.screenadapter.Base.BaseActivity;
import com.my.screenadapter.R;

import org.apache.log4j.Logger;

import butterknife.BindView;
import butterknife.ButterKnife;

public class MsgQueueActivity extends BaseActivity {
Logger logger = Logger.getLogger(MsgQueueActivity.class);

    @BindView(R.id.textView)
    TextView textView;
    @BindView(R.id.button)
    Button button;
    private static final String TAG = "MsgQueueActivity";
    Handler myHandler =new Handler(){
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            Log.i(TAG, "handleMessage: ====msg.what=="+msg.what);
            Object obj = msg.obj;
            if (obj != null) {
                textView.setText((String)obj);
            }
            switch (msg.what){
                case 0:
                    break;
                case 1:
                    break;
            }
        }
    };

    @Override
    protected void init() {

        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Message obtain = Message.obtain();
                myHandler.sendMessageDelayed(obtain, 4000);
                finish();
            }
        });
    }

    @Override
    protected int initLayoutId() {
        return R.layout.activity_handler2;
    }

    public void sendEmpty(View view) {
        Message obtain = Message.obtain();
        obtain.obj = "sendEmpty";
        myHandler.sendMessageDelayed(obtain,0);
        for (int i = 0; i < 5; i++) {
            sendDelay(null);
        }
    }

    public void sendDelay(View view) {
        boolean b = myHandler.hasMessages(0);
        logger.info("hasssss === "+b);
        if (!myHandler.hasMessages(0)){
            myHandler.sendEmptyMessageDelayed(0,1000*10);
        }

    }

    public void sendDelayMuti(View view) {
        logger.info("sendDelayMuti === ");
        for (int i = 0; i < 5; i++) {
            myHandler.sendEmptyMessageDelayed(1,1000*2);
        }

    }
}
